package com.service.system.order.impl;

import com.dao.OrderPayMapper;
import com.dao.UserInfoMapper;
import com.entity.system.OrderPay;
import com.entity.system.UserInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.system.order.OrderPayService;
import com.util.Const;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderPayServiceImpl implements OrderPayService {

    @Autowired
    OrderPayMapper orderPayMapper;

    @Autowired
    UserInfoMapper userInfoMapper;

    @Override
    public Map<String, Object> fundOrderPayList(Map<String, String> map) {
        Map<String,Object> map1 = new HashMap<>();
        int pageSize = 10;
        int pageNum = 1;
        if(StringUtils.isNotEmpty(map.get("pageSize"))){
            pageSize = Integer.parseInt(map.get("pageSize"));
        }
        if(StringUtils.isNotEmpty(map.get("pageNum"))){
            pageNum = Integer.parseInt(map.get("pageNum"));
        }
        PageHelper.startPage(pageNum,pageSize);
        List<OrderPay> orderPay = orderPayMapper.fundOrderPayList(map);
        PageInfo<OrderPay> pageInfo = new PageInfo<>(orderPay);
        List<OrderPay> orderPays = pageInfo.getList();
        for(OrderPay orderPay1 : orderPays){
            UserInfo userInfo = userInfoMapper.findUserById(orderPay1.getUserId());
            if(null != userInfo){
                orderPay1.setPhone(userInfo.getPhone());
                orderPay1.setNickName(userInfo.getNickName());
                if(userInfo.getSex() == 0){
                    orderPay1.setSex("男");
                }else {
                    orderPay1.setSex("女");
                }
            }
        }
        map1.put("code", Const.SUCCESS_CODE);
        map1.put("message","查询成功");
        map1.put("orderPayList",orderPays);
        map1.put("page",pageInfo);
        return map1;
    }
}
